library(httr)
library(jsonlite)
library(ggmap)
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
# API Key
# 1 get API Key
api <- "AIzaSyDDYCpiSuiLczF-JJ7bwiWbtwNyK88YSSM"
# 2 register key
register_google(key = api)
# Generate Map
# Save map for Berlin
blnmap <- get_map("Berlin", zoom = 11)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=Berlin&zoom=11&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-JJ7bwiWbtwNyK88YSSM
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Berlin&key=xxx-JJ7bwiWbtwNyK88YSSM
# Visualize map
ggmap(blnmap)

# this way, we can basically get any map we want
ggmap(get_map("India", zoom = 5))
## Source : https://maps.googleapis.com/maps/api/staticmap?center=India&zoom=5&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-JJ7bwiWbtwNyK88YSSM
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=India&key=xxx-JJ7bwiWbtwNyK88YSSM

# Layer Points on Map
# Create a data point
HertieSchool <- data.frame(lat = 52.5, lon = 13.4)
# Layer the data point on top of the map
ggmap(blnmap) +
geom_point(data = HertieSchool, aes(x = lon, y = lat), colour = "red", size = 3) +
labs(title = "Hertie School of Governance")
